import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '../layout' //布局页
import notFoundRoute from '../views/error/404.vue'

Vue.use(VueRouter)

//解决重复点击左侧菜单的报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


export const asyncRoutes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/',
    component: Layout,
    meta: {
      title: "首页",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/index.vue'),
        meta: {
          title: "首页",
        }
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    meta: {
      title: "充电站管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/station',
        name: 'station',
        component: () => import('@/views/station/index.vue'),
        meta: {
          title: "充电站管理",
        }
      },
      {
        path: '/station/detail/:id',
        name: 'stationDetail',
        component: () => import('@/views/station/detail.vue'),
      },
      {
        path: '/rule',
        name: 'rule',
        component: () => import('@/views/rule/index.vue'),
        meta: {
          title: "规则管理",
        }
      },
    ]
  },
  {
    path: '/order',
    component: Layout,
    meta: {
      title: "订单管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'order-real',
        name: 'orderReal',
        component: () => import('@/views/order/index.vue'),
        meta: {
          title: "实时管理",
        }
      },
      {
        path: 'order-history',
        name: 'orderHistory',
        component: () => import('@/views/order/index2.vue'),
        meta: {
          title: "历史订单",
        }
      },
      {
        path: 'detail/:id',
        name: 'orderDetail',
        component: () => import('@/views/order/detail.vue'),
        meta: {
          title: "订单详情",
        }
      }
    ]
  },
  {
    path: '/home',
    component: Layout,
    meta: {
      title: "会员管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: '/member',
        name: 'member',
        component: () => import('@/views/member/index.vue'),
        meta: {
          title: "会员管理",
        }
      }
    ]
  },
  {
    path: '/config',
    component: Layout,
    meta: {
      title: "配置管理",
      icon: 'el-icon-s-custom',
    },
    children: [
      {
        path: 'policy',
        name: 'policy',
        component: () => import('@/views/policy/index.vue'),
        meta: {
          title: "协议配置",
        }
      },
      {
        path: 'wx',
        name: 'wx',
        component: () => import('@/views/wxConfig/index.vue'),
        meta: {
          title: "微信配置",
        }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/menu',
    meta: {
      title: "系统管理",
      icon: 'el-icon-s-custom',
    },
    name: 'system',
    children: [
      {
        path: 'menu',
        name: 'menu',
        component: () => import('@/views/menu/index.vue'),
        meta: {
          title: "菜单管理",
        }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/role/index.vue'),
        meta: {
          title: "角色管理",
        }
      },
      {
        path: 'user',
        name: 'user',
        component: () => import('@/views/user/index.vue'),
        meta: {
          title: "用户管理",
        }
      },
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/Login'),
    meta: {
      title: "欢迎登录",
    },
    hidden: true //导航菜单忽略选项
  },
  {
    path: '/404',
    meta: {
      title: "页面走丢了",
    },
    component: notFoundRoute,
    hidden: true //导航菜单忽略选项
  },
]


const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes: asyncRoutes
})

export default router
